package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SubDevice;
import com.ruoyi.system.domain.dto.req.AssetAccountReqDTO;
import com.ruoyi.system.service.SubDeviceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 辅助设备
 */
@RestController
@RequestMapping("/system/subDevice")
public class SubDeviceController extends BaseController {

    @Resource
    private SubDeviceService subDeviceService;

    /**
     * 辅助设备数
     *
     * @return
     */
    @RequestMapping("/statistic/totalCount")
    public AjaxResult totalCount() {
        return success(subDeviceService.queryTotalCount());
    }

    /**
     * 查询计量设备列表
     *
     * @param reqDTO
     * @return
     */

    @PostMapping("/subDeviceList")
    public TableDataInfo testSubAccountList(@RequestBody AssetAccountReqDTO reqDTO) {

        return getDataTable(subDeviceService.querySubDeviceList(reqDTO));
    }

    /**
     * 删除计量设备
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/delSubDevice")
    public AjaxResult deleteSubDevice(@RequestBody AssetAccountReqDTO reqDTO) {
        subDeviceService.deleteSubDevice(reqDTO);
        return success();
    }

    /**
     * 添加计量设备
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/insertSubDevice")
    public AjaxResult insertSubDevice(@RequestBody SubDevice reqDTO) {
        subDeviceService.insertSubDevice(reqDTO);
        return success();
    }

    /**
     * 更新主设备信息
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/updateSubDevice")
    public AjaxResult updateSubDevice(@RequestBody SubDevice reqDTO) {
        subDeviceService.updateSubDevice(reqDTO);
        return success();
    }

    /**
     * 根据主设备sn查询辅助设备列表
     * @param mainDeviceSn
     * @return
     */
    @PostMapping("/listByMainDevice/{mainDeviceSn}")
    public AjaxResult subDeviceList(@PathVariable String mainDeviceSn) {
        return success(subDeviceService.subDeviceListByMainDeviceSn(mainDeviceSn));
    }


}
